/*
 * @Descripttion: 
 * @version: 
 * @Author: wtzhang
 * @Date: 2021-07-20 15:30:18
 * @LastEditors: wtzhang
 * @LastEditTime: 2021-07-20 16:50:06
 */

import { ref } from 'vue'
// 引入axios
import axios from 'axios'
export default function <T>(url: string) {
  const loading = ref(true) // 正在加载动画
  const data = ref<T | null>(null) // 请求成功返回的数据
  const errorMsg = ref('') // 错误信息
  // 请求
  axios.get(url).then(res => {
    // console.log(res);
    
    loading.value = false
    data.value = res.data
  }).catch(e => {
    loading.value = false
    errorMsg.value = e.message || '未知错误'
  })
  return {
    loading,
    data,
    errorMsg
  }
}